package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.entity.Codes;

import net.sf.json.JSONObject;

public class BaseCarInfoAjaxAction extends TmsAjaxAction {

	@Override
	public void process(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws TmsException {
		Car car = Car.getInstance();

		String vin = (String) uc.getParameter("vin");
		car = car.findCarBaseInfoByVin(vin);

		JSONObject json = new JSONObject();
		if(car!=null){
			json.put("vendorCode", car.getVendorCode());
			json.put("modelCode", car.getModelCode());
			json.put("carType", car.getCarType());
			json.put("countryStyle", car.getCountryStyle());
			json.put("carUse", car.getCarUse());
			json.put("cardType", car.getCardType());
			json.put("registerCardNo", car.getRegisterCardNo());
			json.put("regDate", car.getRegDate());
			json.put("ownerType", car.getOwnerType());
			json.put("carOwnerIdCardNo", car.getCarOwnerIdCardNo());
			json.put("ownerOrgNo", car.getOwnerOrgNo());
			json.put("carOwner", car.getCarOwner());
			json.put("ownerPhone", car.getOwnerPhone());
			json.put("ownerAddress", car.getOwnerAddress());
			Codes code = Codes.getInstance();
			json.put("carUseName", code.getItemValueByItemIdAndItemCode(Codes.USER_NATURE,car.getCarUse()));
			json.put("carTypeName", code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_TYPE,car.getCarType()));
			json.put("countryStyleName",code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_COUNTRY,car.getCountryStyle()));
			json.put("cardTypeName",code.getItemValueByItemIdAndItemCode(Codes.PLATE_TYPE,car.getCardType()));
		}else{
			json.put("vendorCode","");
			json.put("modelCode","");
			json.put("carType", "");
			json.put("countryStyle","");
			json.put("carUse","");
			json.put("cardType","");
			json.put("registerCardNo","");
			json.put("regDate", "");
			json.put("ownerType","");
			json.put("carOwnerIdCardNo","");
			json.put("ownerOrgNo", "");
			json.put("carOwner","");
			json.put("ownerPhone","");
			json.put("ownerAddress","");
			json.put("carUseName", "");
			json.put("carTypeName","");
			json.put("countryStyleName","");
			json.put("cardTypeName","");
		}
		
		responseValues(response, json.toString(), TEXT);
	}
}
